<?php

use yii\helpers\Html;
use yii\helpers\Url;
use kartik\grid\GridView;
use yii\widgets\DetailView;
use kartik\slider\Slider;
use yii\bootstrap\Modal;


/**
* @var yii\web\View $this
* @var yiike\store\models\OrderStore $model
*/
$copyParams = $model->attributes;

$this->title = '订单信息';
$this->params['breadcrumbs'][] = ['label' => '订单管理', 'url' => ['index']];
$this->params['breadcrumbs'][] = ['label' => (string)$model->id, 'url' => ['view', 'id' => $model->id]];
?>
<!-- flash message -->
<?php if (\Yii::$app->session->getFlash('message') !== null) : ?>
<div class="">
    <span class="alert alert-success alert-dismissible callout callout-success col-lg-12" role="alert">
        <button type="button" class="close" data-dismiss="alert" aria-label="Close">
        <span aria-hidden="true">&times;</span></button>
        <?= \Yii::$app->session->getFlash('message') ?>
    </span>
</div>
<?php endif; ?>

<div class=" ">
<div class="alert  bg-info col-lg-12">
    <div style="width: 80%;margin: 20px auto;">
        <?=\kartik\slider\Slider::widget([
            'name' => 'rating_5',
            'value' => $model->status,
            'sliderColor'=>Slider::TYPE_WARNING,
            'handleColor'=>Slider::TYPE_WARNING,
            'options' => ['disabled' => $model->status == 4, 'style' => 'width:100%;'],
            'pluginOptions'=>[
                'min' => 0,
                'max' => $model->status == 4 ? 4 : 3,
                'step' => 1,
                'tooltip'=>'always',
                'formatter'=>new yii\web\JsExpression("function(val) {
                    var status = ['买家已下单', '买家已付款', '商家已发货' , '交易已收货', '交易取消'];
                    return status[val];
            }")
            ]
        ]);
        ?>
    </div>

    <div class="text-center hidden">
        <button type="button" class="btn btn-info">付款</button>
            <button type="button" class="btn btn-warning">发货</button>
            <button type="button" class="btn btn-danger">退款</button>
    </div>
</div>
</div>

<div class="row" style="margin-top: 20px;">
    <div class="col-lg-6">
        <div class=" box box-info">
            <div class="box-header bg-info">
                <i class="fa fa-user"></i>
                <h3 class="box-title">买家信息</h3>
            </div>
            <div class="box-body">
                <?= DetailView::widget([
                    'model' => $model,
                    'attributes' => [
                        'order.name',
                        'order.mobile',
                        [
                            'label' => '地区',
                            'value' => function ($model) {
                                $order = $model->order;
                                return $order->province .' '. $order->city.' '. $order->district;
                            }
                        ],
                        [
                            'attribute' => 'order.address',
                            'value' => function ($model) {
                                $order = $model->order;
                                return $order->province .''. $order->city.''. $order->district.''. $order->address;
                            }
                        ],
                        'order.memo',
                    ],
                ]); ?>
            </div>

        </div>
    </div>
    <div class="col-lg-6 ">
        <div class=" box box-info">
            <div class="box-header bg-info">
                <i class="fa fa-calendar"></i>
                <h3 class="box-title">订单信息</h3>
            </div>
            <div class="box-body">
                <?= DetailView::widget([
                    'model' => $model,
                    'attributes' => [
                        'trade_id',
                        [
                            'label' => '付款商户号',
                            'value' => function($model) {
                                return $model->uniontid ? : $model->order->uniontid;
                            }
                        ],
                        'order.created_at:datetime',
                        'pay_at:datetime',
                        'express_at:datetime',
                    ],
                ]); ?>
            </div>
        </div>
    </div>
</div>

<div class="box box-solid giiant-crud order-store-view">
    <div class="box-header bg-info">
        <div class="box-title">
            <i class="fa fa-list"></i>
            商品信息
        </div>
    </div>
    <div class="box-body">
        <?php
            $dataProvider = new \yii\data\ActiveDataProvider();
            $dataProvider->models =  $model->orderGoods;

        echo GridView::widget([
            'dataProvider' => $dataProvider,
            'toggleData' => false,
            'showPageSummary' => false,
            'layout' => '{items}',
//            'responsiveWrap' => false,
            'tableOptions' => ['class' => 'table table-striped table-bordered table-hover'],

            'columns' => [
                [
                    'attribute' => 'logo',
                    'width' => '80px',
                    'content' => function ($model) {
                        return Html::img($model->logo, ['width' => 60]);
                    }
                ],
                [
                    'attribute' => 'goods_sn',
                    'width' => '120px',
                ],
                'title',
                'spec',
                'cost_price',
                'num',
                [
                    'attribute' => 'total',
                    'value' => function ($model) {
                        return $model->cost_price * $model->num;
                    }
                ]
            ]
        ]);
        ?>
        <div class="text-right">
            <b>合计: <?=$model->settlement ?></b>
        </div>
    </div>
</div>


<div class="box box-warning giiant-crud order-store-view">
    <div class="box-header bg-warning">
        <i class="fa fa-truck"></i>
        <h3 class="box-title">物流信息</h3>
        <?php
        Modal::begin([
            'header' => '修改物流信息',
            'toggleButton' => ['label' => '修改', 'class' => 'btn btn-warning btn-sm'],
        ]);
        echo $this->render('_express', ['model' =>$model]);
        ?>

        <?php Modal::end(); ?>
    </div>
    <div class="box-body">
        <?php
        if ($model->status == 1 || Yii::$app->request->get('express') == 1) {
            echo $this->render('_express', ['model' =>$model]);
        }
        else {
            echo DetailView::widget([
                'model' => $model,
                'attributes' => [
                    'express_name',
                    'express_no'
                ],
            ]);
        }
        ?>
    </div>
</div>
